<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nrf51/Source/ext_sensors/adns2080/adns2080.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51 General Code Examples
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('adns2080_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">nrf51/Source/ext_sensors/adns2080/adns2080.c</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001  <span class="comment">/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> */</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;stdbool.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="adns2080_8h.html" title="ADNS2080 mouse sensor driver.">adns2080.h</a>&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="sdio_8h.html" title="2-wire serial interface driver (compatible with ADNS2080 mouse sensor driver)">sdio.h</a>&quot;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="comment">/*lint ++flb &quot;Enter library region&quot; */</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#define ADNS2080_PRODUCT_ID (0x2AU) </span>
<a name="l00022"></a>00022 <span class="preprocessor">#define ADNS2080_RESET_NUMBER (0x5AU) </span>
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="comment">/* ADNS2080 register addresses */</span>
<a name="l00025"></a>00025 <span class="preprocessor">#define REG_PROD_ID (0x00U) </span>
<a name="l00026"></a>00026 <span class="preprocessor">#define REG_REV_ID (0x01U) </span>
<a name="l00027"></a>00027 <span class="preprocessor">#define REG_MOTION_ST (0x02U) </span>
<a name="l00028"></a>00028 <span class="preprocessor">#define REG_DELTA_X (0x03U) </span>
<a name="l00029"></a>00029 <span class="preprocessor">#define REG_DELTA_Y (0x04U) </span>
<a name="l00030"></a>00030 <span class="preprocessor">#define REG_SQUAL (0x05U) </span>
<a name="l00031"></a>00031 <span class="preprocessor">#define REG_SHUT_HI (0x06U) </span>
<a name="l00032"></a>00032 <span class="preprocessor">#define REG_SHUT_LO (0x07U) </span>
<a name="l00033"></a>00033 <span class="preprocessor">#define REG_PIX_MAX (0x08U) </span>
<a name="l00034"></a>00034 <span class="preprocessor">#define REG_PIX_ACCUM (0x09U) </span>
<a name="l00035"></a>00035 <span class="preprocessor">#define REG_PIX_MIN (0x0AU) </span>
<a name="l00036"></a>00036 <span class="preprocessor">#define REG_PIX_GRAB (0x0BU) </span>
<a name="l00037"></a>00037 <span class="preprocessor">#define REG_DELTA_XY_HIGH (0x0CU) </span>
<a name="l00038"></a>00038 <span class="preprocessor">#define REG_MOUSE_CTRL (0x0DU) </span>
<a name="l00039"></a>00039 <span class="preprocessor">#define REG_RUN_DOWNSHIFT (0x0EU) </span>
<a name="l00040"></a>00040 <span class="preprocessor">#define REG_REST1_PERIOD (0x0FU) </span>
<a name="l00041"></a>00041 <span class="preprocessor">#define REG_REST1_DOWNSHIFT (0x10U) </span>
<a name="l00042"></a>00042 <span class="preprocessor">#define REG_REST2_PERIOD (0x11U) </span>
<a name="l00043"></a>00043 <span class="preprocessor">#define REG_REST2_DOWNSHIFT (0x12U) </span>
<a name="l00044"></a>00044 <span class="preprocessor">#define REG_REST3_PERIOD (0x13U) </span>
<a name="l00045"></a>00045 <span class="preprocessor">#define REG_PERFORMANCE (0x22U) </span>
<a name="l00046"></a>00046 <span class="preprocessor">#define REG_RESET (0x3aU) </span>
<a name="l00047"></a>00047 <span class="preprocessor">#define REG_NOT_REV_ID (0x3fU) </span>
<a name="l00048"></a>00048 <span class="preprocessor">#define REG_LED_CTRL (0x40U) </span>
<a name="l00049"></a>00049 <span class="preprocessor">#define REG_MOTION_CTRL (0x41U) </span>
<a name="l00050"></a>00050 <span class="preprocessor">#define REG_BURST_READ_FIRST (0x42U) </span>
<a name="l00051"></a>00051 <span class="preprocessor">#define REG_BURST_READ_LAST (0x44U) </span>
<a name="l00052"></a>00052 <span class="preprocessor">#define REG_REST_MODE_CONFIG (0x45U) </span>
<a name="l00053"></a>00053 <span class="preprocessor">#define REG_MOTION_BURST (0x63U) </span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="comment">/* ADNS2080 register bits */</span>
<a name="l00056"></a>00056 <span class="preprocessor">#define REG_MOUSE_CTRL_POWERDOWN (0x02U) </span>
<a name="l00057"></a>00057 <span class="preprocessor">#define REG_MOTION_CTRL_MOT_A (0x80U) </span>
<a name="l00058"></a>00058 <span class="preprocessor">#define REG_MOTION_CTRL_MOT_S (0x40U) </span>
<a name="l00059"></a>00059 <span class="preprocessor">#define REG_MOUSE_CTRL_RES_EN (0x40U) </span>
<a name="l00060"></a>00060 <span class="preprocessor">#define REG_MOUSE_CTRL_BIT_REPORTING (0x80U) </span>
<a name="l00062"></a><a class="code" href="group__nrf__drivers__adns2080.html#gae6c580be751e0dd5a4e4828a36d8fcd2">00062</a> <span class="preprocessor">void adns2080_movement_read(int16_t *deltaX, int16_t *deltaY)</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>{
<a name="l00064"></a>00064   uint8_t delta_x; 
<a name="l00065"></a>00065   uint8_t delta_y; 
<a name="l00066"></a>00066   uint8_t delta_xy_high; 
<a name="l00067"></a>00067   uint8_t delta_x_high; 
<a name="l00068"></a>00068   uint8_t delta_y_high; 
<a name="l00070"></a>00070   uint16_t u16_deltaX; 
<a name="l00071"></a>00071   uint16_t u16_deltaY; 
<a name="l00073"></a>00073   delta_x = <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_DELTA_X);
<a name="l00074"></a>00074   delta_y = <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_DELTA_Y);
<a name="l00075"></a>00075 
<a name="l00076"></a>00076   <span class="keywordflow">if</span> (<a class="code" href="group__nrf__drivers__adns2080.html#ga6db887a23708021cc3576e12507dc66d">adns2080_motion_bits_read</a>() == <a class="code" href="group__nrf__drivers__adns2080.html#gga31fa2de64250e9b0b6b90079dc0c268facd0f3314b9898064af180862fc2ea60c">ADNS2080_MOTION_BITS_12</a>)
<a name="l00077"></a>00077   {
<a name="l00078"></a>00078     <span class="comment">// In 12 bit mode the upper 4 bits are stored in a separate register</span>
<a name="l00079"></a>00079     <span class="comment">// where first 4 upper bits are for delta_x and lower 4 bits for delta_y.</span>
<a name="l00080"></a>00080     delta_xy_high = <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_DELTA_XY_HIGH);
<a name="l00081"></a>00081 
<a name="l00082"></a>00082     delta_x_high = ((delta_xy_high &amp; 0xF0) &gt;&gt; 4);
<a name="l00083"></a>00083     delta_y_high = (delta_xy_high &amp; 0x0F);
<a name="l00084"></a>00084 
<a name="l00085"></a>00085     <span class="comment">// Check if MSB is 1. If it is, this is a negative number and we have</span>
<a name="l00086"></a>00086     <span class="comment">// to fill the upper unused bits with 1s.</span>
<a name="l00087"></a>00087     <span class="keywordflow">if</span> (delta_x_high &amp; 0x08)
<a name="l00088"></a>00088     {
<a name="l00089"></a>00089       u16_deltaX = 0xF000;
<a name="l00090"></a>00090     }
<a name="l00091"></a>00091     <span class="keywordflow">else</span>
<a name="l00092"></a>00092     {
<a name="l00093"></a>00093       u16_deltaX = 0x0000;
<a name="l00094"></a>00094     }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="comment">// Check if MSB is 1. If it is, this is a negative number and we have</span>
<a name="l00097"></a>00097     <span class="comment">// to fill the upper unused bits with 1s.</span>
<a name="l00098"></a>00098     <span class="keywordflow">if</span> (delta_y_high &amp; 0x08)
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100       u16_deltaY = 0xF000;
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102     <span class="keywordflow">else</span>
<a name="l00103"></a>00103     {
<a name="l00104"></a>00104       u16_deltaY = 0x0000;
<a name="l00105"></a>00105     }
<a name="l00106"></a>00106 
<a name="l00107"></a>00107     u16_deltaX |= (delta_x_high &lt;&lt; 4) | delta_x;
<a name="l00108"></a>00108     u16_deltaY |= (delta_y_high &lt;&lt; 4) | delta_y;
<a name="l00109"></a>00109   }
<a name="l00110"></a>00110   <span class="keywordflow">else</span> <span class="comment">// Only 8 bits is used for motion data</span>
<a name="l00111"></a>00111   {
<a name="l00112"></a>00112     <span class="comment">// Check if MSB is 1. If it is, this is a negative number and we have</span>
<a name="l00113"></a>00113     <span class="comment">// to fill the upper unused bits with 1s.</span>
<a name="l00114"></a>00114     <span class="keywordflow">if</span> (delta_x &amp; 0x80)
<a name="l00115"></a>00115     {
<a name="l00116"></a>00116       u16_deltaX = 0xFF00;
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118     <span class="keywordflow">else</span>
<a name="l00119"></a>00119     {
<a name="l00120"></a>00120       u16_deltaX = 0x0000;
<a name="l00121"></a>00121     }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     <span class="comment">// Check if MSB is 1. If it is, this is a negative number and we have</span>
<a name="l00124"></a>00124     <span class="comment">// to fill the upper unused bits with 1s.</span>
<a name="l00125"></a>00125     <span class="keywordflow">if</span> (delta_y &amp; 0x80)
<a name="l00126"></a>00126     {
<a name="l00127"></a>00127       u16_deltaY = 0xFF00;
<a name="l00128"></a>00128     }
<a name="l00129"></a>00129     <span class="keywordflow">else</span>
<a name="l00130"></a>00130     {
<a name="l00131"></a>00131       u16_deltaY = 0x0000;
<a name="l00132"></a>00132     }
<a name="l00133"></a>00133 
<a name="l00134"></a>00134     u16_deltaX |= delta_x;
<a name="l00135"></a>00135     u16_deltaY |= delta_y;
<a name="l00136"></a>00136   }
<a name="l00137"></a>00137   
<a name="l00138"></a>00138   *deltaX = (int16_t)u16_deltaX;
<a name="l00139"></a>00139   *deltaY = (int16_t)u16_deltaY;
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00142"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga6db887a23708021cc3576e12507dc66d">00142</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga31fa2de64250e9b0b6b90079dc0c268f">adns2080_motion_bits_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga6db887a23708021cc3576e12507dc66d">adns2080_motion_bits_read</a>(<span class="keywordtype">void</span>)
<a name="l00143"></a>00143 {
<a name="l00144"></a>00144   <span class="comment">/* Read the most significant bit */</span>
<a name="l00145"></a>00145   <span class="keywordflow">return</span> (<a class="code" href="group__nrf__drivers__adns2080.html#ga31fa2de64250e9b0b6b90079dc0c268f">adns2080_motion_bits_t</a>)((<a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_MOUSE_CTRL) &gt;&gt; 7) &amp; 0x01);
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 
<a name="l00148"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga801baebecd8050a212f8a8a51a9622b1">00148</a> <span class="keywordtype">bool</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga801baebecd8050a212f8a8a51a9622b1">adns2080_is_motion_detected</a>(<span class="keywordtype">void</span>)
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150   <span class="keywordflow">return</span> ((<a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_MOTION_ST) &amp; 0x80) != 0);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 
<a name="l00153"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga01a612c0b8e060261eb037b1385852dd">00153</a> uint8_t <a class="code" href="group__nrf__drivers__adns2080.html#ga01a612c0b8e060261eb037b1385852dd">adns2080_product_id_read</a>(<span class="keywordtype">void</span>)
<a name="l00154"></a>00154 {
<a name="l00155"></a>00155   <span class="keywordflow">return</span> <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_PROD_ID);
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga0e5027fd02ac3036c0f7d99e6d197cfa">00158</a> uint8_t <a class="code" href="group__nrf__drivers__adns2080.html#ga0e5027fd02ac3036c0f7d99e6d197cfa">adns2080_revision_id_read</a>(<span class="keywordtype">void</span>)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160   <span class="keywordflow">return</span> <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_REV_ID);
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 
<a name="l00163"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga7abcaefa87c1e9452357ceaf16b0f367">00163</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga7abcaefa87c1e9452357ceaf16b0f367">adns2080_init</a>(<span class="keywordtype">void</span>)
<a name="l00164"></a>00164 {
<a name="l00165"></a>00165   <a class="code" href="group__nrf__drivers__sdio.html#gafd362e60216c5346709cac28c7cc175b">sdio_init</a>();
<a name="l00166"></a>00166   <a class="code" href="group__nrf__drivers__adns2080.html#ga1fb641e4bbbd7f5aa99f59d34367cd6b">adns2080_reset</a>();
<a name="l00167"></a>00167 
<a name="l00168"></a>00168   <span class="keywordflow">if</span> (<a class="code" href="group__nrf__drivers__adns2080.html#ga01a612c0b8e060261eb037b1385852dd">adns2080_product_id_read</a>() != ADNS2080_PRODUCT_ID)
<a name="l00169"></a>00169   {
<a name="l00170"></a>00170     <span class="keywordflow">return</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0af712577c3d06b79119d08728bd326143">ADNS2080_CHIP_NOT_DETECTED</a>;
<a name="l00171"></a>00171   }
<a name="l00172"></a>00172   
<a name="l00173"></a>00173   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_BURST_READ_FIRST, REG_DELTA_X);
<a name="l00174"></a>00174   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_BURST_READ_LAST, REG_DELTA_Y);
<a name="l00175"></a>00175 
<a name="l00176"></a>00176   <span class="keywordflow">return</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>;
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga1fb641e4bbbd7f5aa99f59d34367cd6b">00179</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga1fb641e4bbbd7f5aa99f59d34367cd6b">adns2080_reset</a>(<span class="keywordtype">void</span>)
<a name="l00180"></a>00180 {
<a name="l00181"></a>00181   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_RESET, ADNS2080_RESET_NUMBER);
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00184"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga60d713c7a98bf1b326ec2cc51987fc44">00184</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga60d713c7a98bf1b326ec2cc51987fc44">adns2080_powerdown</a>(<span class="keywordtype">void</span>)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_MOUSE_CTRL, REG_MOUSE_CTRL_POWERDOWN);
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00189"></a><a class="code" href="group__nrf__drivers__adns2080.html#gad6d99e8f21de3f6d728ebe032e86321c">00189</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#gad6d99e8f21de3f6d728ebe032e86321c">adns2080_wakeup</a>(<span class="keywordtype">void</span>)
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191   <a class="code" href="group__nrf__drivers__adns2080.html#ga1fb641e4bbbd7f5aa99f59d34367cd6b">adns2080_reset</a>();
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 
<a name="l00194"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga69ec7d764a60e9b9f518a69e7e402b24">00194</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga69ec7d764a60e9b9f518a69e7e402b24">adns2080_motion_interrupt_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#ga0a2e533ff5cb6517085859827320e103">motion_output_polarity_t</a> polarity, <a class="code" href="group__nrf__drivers__adns2080.html#gaf829efdc343990811ba18dd86c68ef41">motion_output_sensitivity_t</a> sensitivity)
<a name="l00195"></a>00195 {
<a name="l00196"></a>00196   uint8_t databyte = 0;
<a name="l00197"></a>00197   <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>;
<a name="l00198"></a>00198 
<a name="l00199"></a>00199   <span class="keywordflow">switch</span> (polarity)
<a name="l00200"></a>00200   {
<a name="l00201"></a>00201     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga0a2e533ff5cb6517085859827320e103a3af88cabf9c235c4819ef9d6ba3296b8">ADNS2080_MOTION_OUTPUT_POLARITY_LOW</a>:
<a name="l00202"></a>00202       databyte = 0; <span class="comment">// Clear REG_MOTION_CTRL_MOT_A bit</span>
<a name="l00203"></a>00203     <span class="keywordflow">break</span>;
<a name="l00204"></a>00204 
<a name="l00205"></a>00205     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga0a2e533ff5cb6517085859827320e103a21e1a4f8918c66c9756657f7439664df">ADNS2080_MOTION_OUTPUT_POLARITY_HIGH</a>:
<a name="l00206"></a>00206       databyte = REG_MOTION_CTRL_MOT_A;
<a name="l00207"></a>00207     <span class="keywordflow">break</span>;
<a name="l00208"></a>00208 
<a name="l00209"></a>00209     <span class="keywordflow">default</span>:
<a name="l00210"></a>00210       status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a4c8338bb73d258fb9a3afa12ed4fab6e">ADNS2080_INVALID_PARAMETER</a>;
<a name="l00211"></a>00211     <span class="keywordflow">break</span>;
<a name="l00212"></a>00212   }
<a name="l00213"></a>00213 
<a name="l00214"></a>00214   <span class="keywordflow">switch</span> (sensitivity)
<a name="l00215"></a>00215   {
<a name="l00216"></a>00216     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaf829efdc343990811ba18dd86c68ef41ac914f711978a260c7db987d8130b14c6">ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL</a>:
<a name="l00217"></a>00217       databyte &amp;= ~(REG_MOTION_CTRL_MOT_S);
<a name="l00218"></a>00218     <span class="keywordflow">break</span>;
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaf829efdc343990811ba18dd86c68ef41a44ab7166499d9be9e69457f3507bff66">ADNS2080_MOTION_OUTPUT_SENSITIVITY_EDGE</a>:
<a name="l00221"></a>00221       databyte |= (REG_MOTION_CTRL_MOT_S);
<a name="l00222"></a>00222     <span class="keywordflow">break</span>;
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="keywordflow">default</span>:
<a name="l00225"></a>00225       status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a4c8338bb73d258fb9a3afa12ed4fab6e">ADNS2080_INVALID_PARAMETER</a>;
<a name="l00226"></a>00226     <span class="keywordflow">break</span>;
<a name="l00227"></a>00227   }
<a name="l00228"></a>00228 
<a name="l00229"></a>00229   <span class="keywordflow">if</span> (status == <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>)
<a name="l00230"></a>00230   {
<a name="l00231"></a>00231     <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_MOTION_CTRL, databyte);
<a name="l00232"></a>00232   }
<a name="l00233"></a>00233 
<a name="l00234"></a>00234   <span class="keywordflow">return</span> status;
<a name="l00235"></a>00235 }
<a name="l00236"></a>00236 
<a name="l00237"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga6671aadea596e9200f480ce0508eb776">00237</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga6671aadea596e9200f480ce0508eb776">adns2080_resolution_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#gaa0379c80ab64ff7a2532eb33fd823d0f">adns2080_resolution_t</a> resolution)
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239   uint8_t databyte = <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_MOUSE_CTRL);
<a name="l00240"></a>00240   <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>;
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <span class="comment">// Enable resolution settings on REG_MOUSE_CTRL [4:2]</span>
<a name="l00243"></a>00243   databyte |= (REG_MOUSE_CTRL_RES_EN);
<a name="l00244"></a>00244 
<a name="l00245"></a>00245   <span class="keywordflow">switch</span> (resolution)
<a name="l00246"></a>00246   {
<a name="l00247"></a>00247     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fa75e7d55b0d3d895e93ae34bcabc36930">ADNS2080_RESOLUTION_250DPI</a>:
<a name="l00248"></a>00248     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fa3536fcd2eea68137e547fdacae1bcd55">ADNS2080_RESOLUTION_500DPI</a>:
<a name="l00249"></a>00249     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fabcd6c08edd9e815b6c9f605bca2fb9e6">ADNS2080_RESOLUTION_1000DPI</a>:
<a name="l00250"></a>00250     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fabab5302b37ed9c177843944931b5371e">ADNS2080_RESOLUTION_1250DPI</a>:
<a name="l00251"></a>00251     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fa6168ba0c1dc389709c3b057ee3448a62">ADNS2080_RESOLUTION_1500DPI</a>:
<a name="l00252"></a>00252     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0fac6d9218e253c98616116a984498446a8">ADNS2080_RESOLUTION_1750DPI</a>:
<a name="l00253"></a>00253     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#ggaa0379c80ab64ff7a2532eb33fd823d0faa131317b2b497f0e95e301997a962607">ADNS2080_RESOLUTION_2000DPI</a>:
<a name="l00254"></a>00254       <span class="comment">// Clear resolution bits [4:2]</span>
<a name="l00255"></a>00255       databyte &amp;= ~(0x1C); <span class="comment">// 0b00011100;</span>
<a name="l00256"></a>00256       <span class="comment">// Set resolution bits</span>
<a name="l00257"></a>00257       databyte |= (uint8_t)((uint8_t)resolution &lt;&lt; 2);
<a name="l00258"></a>00258     <span class="keywordflow">break</span>;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260     <span class="keywordflow">default</span>:
<a name="l00261"></a>00261       status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a4c8338bb73d258fb9a3afa12ed4fab6e">ADNS2080_INVALID_PARAMETER</a>;
<a name="l00262"></a>00262     <span class="keywordflow">break</span>;
<a name="l00263"></a>00263   }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265   <span class="keywordflow">if</span> (status == <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>)
<a name="l00266"></a>00266   {
<a name="l00267"></a>00267     <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_MOUSE_CTRL, databyte);
<a name="l00268"></a>00268   }
<a name="l00269"></a>00269 
<a name="l00270"></a>00270   <span class="keywordflow">return</span> status;
<a name="l00271"></a>00271 }
<a name="l00272"></a>00272 
<a name="l00273"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga4a7a8b881d69ad88354a5455724d80aa">00273</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#ga4a7a8b881d69ad88354a5455724d80aa">adns2080_motion_bits_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#ga31fa2de64250e9b0b6b90079dc0c268f">adns2080_motion_bits_t</a> motion_bits)
<a name="l00274"></a>00274 {
<a name="l00275"></a>00275   uint8_t databyte = <a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_MOUSE_CTRL);
<a name="l00276"></a>00276   <a class="code" href="group__nrf__drivers__adns2080.html#ga657b7b313f5cd8ed57cbbf09010e86a0">adns2080_status_t</a> status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>;
<a name="l00277"></a>00277 
<a name="l00278"></a>00278   <span class="keywordflow">switch</span> (motion_bits)
<a name="l00279"></a>00279   {
<a name="l00280"></a>00280     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga31fa2de64250e9b0b6b90079dc0c268fa4bcd85d513b3fd22d72df39cb4fb5c4f">ADNS2080_MOTION_BITS_8</a>:
<a name="l00281"></a>00281       databyte &amp;= ~(REG_MOUSE_CTRL_BIT_REPORTING);
<a name="l00282"></a>00282     <span class="keywordflow">break</span>;
<a name="l00283"></a>00283 
<a name="l00284"></a>00284     <span class="keywordflow">case</span> <a class="code" href="group__nrf__drivers__adns2080.html#gga31fa2de64250e9b0b6b90079dc0c268facd0f3314b9898064af180862fc2ea60c">ADNS2080_MOTION_BITS_12</a>:
<a name="l00285"></a>00285       databyte |= (REG_MOUSE_CTRL_BIT_REPORTING);
<a name="l00286"></a>00286     <span class="keywordflow">break</span>;
<a name="l00287"></a>00287 
<a name="l00288"></a>00288     <span class="keywordflow">default</span>:
<a name="l00289"></a>00289       status = <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a4c8338bb73d258fb9a3afa12ed4fab6e">ADNS2080_INVALID_PARAMETER</a>;
<a name="l00290"></a>00290     <span class="keywordflow">break</span>;
<a name="l00291"></a>00291   }
<a name="l00292"></a>00292 
<a name="l00293"></a>00293   <span class="keywordflow">if</span> (status == <a class="code" href="group__nrf__drivers__adns2080.html#gga657b7b313f5cd8ed57cbbf09010e86a0a36900d375db3b09dbd8c9911b2100d95">ADNS2080_OK</a>)
<a name="l00294"></a>00294   {
<a name="l00295"></a>00295     <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_MOUSE_CTRL, databyte);
<a name="l00296"></a>00296   }
<a name="l00297"></a>00297 
<a name="l00298"></a>00298   <span class="keywordflow">return</span> status;
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300 
<a name="l00301"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga21ef4dd412d7340b1df4c79f8bd5e87e">00301</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga21ef4dd412d7340b1df4c79f8bd5e87e">adns2080_rest_periods_set</a>(uint8_t rest1_period, uint8_t rest2_period, uint8_t rest3_period)
<a name="l00302"></a>00302 {
<a name="l00303"></a>00303   <a class="code" href="group__nrf__drivers__adns2080.html#gafb430f188555285bcf8790a6252b14dd">adns2080_mode_t</a> current_mode = <a class="code" href="group__nrf__drivers__adns2080.html#gad11f08fe46172ea478714722fdd74cf5">adns2080_force_mode_read</a>();
<a name="l00304"></a>00304   <a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">adns2080_force_mode_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#ggafb430f188555285bcf8790a6252b14dda3c44ef7e8b4a68d816270cb787f21821">ADNS2080_MODE_RUN1</a>);
<a name="l00305"></a>00305   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_REST1_PERIOD, rest1_period);
<a name="l00306"></a>00306   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_REST2_PERIOD, rest2_period);
<a name="l00307"></a>00307   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_REST3_PERIOD, rest3_period);
<a name="l00308"></a>00308   <a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">adns2080_force_mode_set</a>(current_mode);
<a name="l00309"></a>00309 }
<a name="l00310"></a>00310 
<a name="l00311"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga9cffab56583fbc577fc0b597eea7bb19">00311</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga9cffab56583fbc577fc0b597eea7bb19">adns2080_downshift_times_set</a>(uint8_t run_to_rest1_mode_time, uint8_t rest1_to_rest2_mode_time, uint8_t rest2_to_rest3_mode_time)
<a name="l00312"></a>00312 {
<a name="l00313"></a>00313   <a class="code" href="group__nrf__drivers__adns2080.html#gafb430f188555285bcf8790a6252b14dd">adns2080_mode_t</a> current_mode = <a class="code" href="group__nrf__drivers__adns2080.html#gad11f08fe46172ea478714722fdd74cf5">adns2080_force_mode_read</a>();
<a name="l00314"></a>00314   <a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">adns2080_force_mode_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#ggafb430f188555285bcf8790a6252b14dda3c44ef7e8b4a68d816270cb787f21821">ADNS2080_MODE_RUN1</a>);
<a name="l00315"></a>00315   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_RUN_DOWNSHIFT, run_to_rest1_mode_time);
<a name="l00316"></a>00316   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_REST1_DOWNSHIFT, rest1_to_rest2_mode_time);
<a name="l00317"></a>00317   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_REST2_DOWNSHIFT, rest2_to_rest3_mode_time);
<a name="l00318"></a>00318   <a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">adns2080_force_mode_set</a>(current_mode);
<a name="l00319"></a>00319 }
<a name="l00320"></a>00320 
<a name="l00321"></a><a class="code" href="group__nrf__drivers__adns2080.html#gad11f08fe46172ea478714722fdd74cf5">00321</a> <a class="code" href="group__nrf__drivers__adns2080.html#gafb430f188555285bcf8790a6252b14dd">adns2080_mode_t</a> <a class="code" href="group__nrf__drivers__adns2080.html#gad11f08fe46172ea478714722fdd74cf5">adns2080_force_mode_read</a>(<span class="keywordtype">void</span>)
<a name="l00322"></a>00322 {
<a name="l00323"></a>00323   <span class="keywordflow">return</span> (<a class="code" href="group__nrf__drivers__adns2080.html#gafb430f188555285bcf8790a6252b14dd">adns2080_mode_t</a>)((<a class="code" href="group__nrf__drivers__sdio.html#ga1ff0f4956042d92b01fc2dbeffe26284">sdio_read_byte</a>(REG_PERFORMANCE) &gt;&gt; 4) &amp; 0x07);
<a name="l00324"></a>00324 }
<a name="l00325"></a>00325 
<a name="l00326"></a><a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">00326</a> <span class="keywordtype">void</span> <a class="code" href="group__nrf__drivers__adns2080.html#ga54da01cd3b8230711d8ed00d5c74326b">adns2080_force_mode_set</a>(<a class="code" href="group__nrf__drivers__adns2080.html#gafb430f188555285bcf8790a6252b14dd">adns2080_mode_t</a> mode)
<a name="l00327"></a>00327 {
<a name="l00328"></a>00328   <a class="code" href="group__nrf__drivers__sdio.html#ga2e5d560f80ba374b7fe18f4e8a565ffd">sdio_write_byte</a>(REG_PERFORMANCE, (uint8_t)((uint8_t)mode &lt;&lt; 4));
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330 
<a name="l00331"></a>00331 <span class="comment">/*lint --flb &quot;Leave library region&quot; */</span> 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>adns2080.c</b>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
